package com.mall.web.util;

import java.util.ArrayList;
import java.util.List;

import com.mall.pojo.User;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.domain.Userinfos;
import com.taobao.api.request.OpenimUsersAddRequest;
import com.taobao.api.response.OpenimUsersAddResponse;

public class AliBaiChuanUtil {
	
	
	
	/*
	 * 阿里百川api
	 */
	private final static String ALIAPI = "http://gw.api.taobao.com/router/rest";
	/*
	 * 阿里百川唯一识别appkey
	 */
	private final static String APPKEY = "23667329";
	/*
	 * 阿里百川唯一识别secret
	 */
	private final static String SECRET = "9c6ea5b9878b71c5de00b2035d6726ea";

	public final static String UID ="hzzhimepanjin-";//用户注册阿里百川uid的前缀
	public final static String PASS ="Hello1234";
	
	public final static String URL_KEY_HIDDEN_FROMALIBAICHUAN ="fromAliBaiChuan";
	public final static String URL_KEY_HIDDEN_TOALIBAICHUAN ="toAliBaiChuan";
	public final static String URL_KEY_HIDDEN_TOALIBAICHUANNAME ="toAliBaiChuanName";
	public final static String URL_KEY_HIDDEN_ALIBAICHUANPASSWORD ="alibaichuanpassword";
	
	/**
	 * 存入阿里百川
	 * @param user
	 * @return
	 */
	public static Boolean insertUserInfoAliBaiChuan(User user) {
		String aliUserId = UID + user.getPhone();
		String aliPass = PASS;
		TaobaoClient client = new DefaultTaobaoClient(ALIAPI, APPKEY, SECRET);
		OpenimUsersAddRequest req = new OpenimUsersAddRequest();

		List<Userinfos> list2 = new ArrayList<Userinfos>();
		Userinfos obj3 = new Userinfos();
		list2.add(obj3);
		obj3.setNick(aliUserId);
		// obj3.setIconUrl("http://xxx.com/xxx");
		// obj3.setEmail("uid@taobao.com");
		// obj3.setMobile(phone);
		// obj3.setTaobaoid("tbnick123");
		obj3.setUserid(aliUserId);
		obj3.setPassword(aliPass);
		// obj3.setRemark("demo");
		// obj3.setExtra("{}");
		// obj3.setCareer("demo");
		// obj3.setVip("{}");
		// obj3.setAddress("demo");
		// obj3.setName("demo");
		// obj3.setAge(123L);
		// obj3.setGender("M");
		// obj3.setWechat("demo");
		// obj3.setQq("demo");
		// obj3.setWeibo("demo");
		req.setUserinfos(list2);
		try {
			OpenimUsersAddResponse rsp = client.execute(req);
		} catch (ApiException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

}
